import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';
import 'package:logging/logging.dart';

import 'home.dart';
import 'huari_page.dart';
import 'loading.dart';
import 'lorin_page.dart';
import 'protocol_service.dart';
import 'routes.dart';

final _logger = Logger('MyApp');

void main() {
  Get.put(ProtocolService());

  Logger.root.level = Level.ALL; // 设置日志级别
  Logger.root.onRecord.listen((record) {
    debugPrint('${record.level.name}: ${record.time}: ${record.message}');
  });

  _logger.finest('最详细日志');
  _logger.finer('详细日志');
  _logger.fine('一般调试信息');
  _logger.config('配置信息');
  _logger.info('普通信息');
  _logger.warning('警告');
  _logger.severe('严重错误');
  _logger.shout('最高级别错误');

  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();

    // 初始化 EasyLoading 相关配置
    Loading.initLoading(darkMode: true);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      routes: {
        '/': (context) => const HomePage(),
        AppRoutes.lorin: (context) => const LorinPage(),
        AppRoutes.huari: (context) => const HuariPage(),
      },
      builder: EasyLoading.init(),
    );
  }
}
